package com.atguigu.gmall.common.util;

import org.springframework.web.HttpRequestHandler;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;

import javax.servlet.http.HttpServletRequest;

/**
 * @Author:lyd
 **/
public class ReqUtil {

    /***
     * 获取当前请求
     * RequestContextHolder 是一个工具类，用于获取当前请求的request和response
     * @return
     */
    public static HttpServletRequest getOldRequest() {
//        HttpServletRequest request = (HttpServletRequest) RequestContextHolder.getRequestAttributes();
        RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
        HttpServletRequest request = null;
        if (requestAttributes != null) {
            request = (HttpServletRequest) requestAttributes.resolveReference(RequestAttributes.REFERENCE_REQUEST);
        }
        return request;
    }
}
